﻿namespace Pibby.Core.Playlist
{
    using System;
    using Pibby.Core.IO;

	public class MediaPlaylist : IPlaylist
	{
		public MediaPlaylist()
		{
			this.Items = new PlaylistItemCollection();
		}

		public static MediaPlaylist LoadFrom(IFolder folder)
		{
			var lister = new FileListVisitor();

			lister.ListContentsOf(folder, 
								System.IO.SearchOption.TopDirectoryOnly,
								FileConstants.Mp3FileFilter);

			return LoadFrom(lister.Items);
		}

		public static MediaPlaylist LoadFrom(IFileCollection files)
		{
			var collection = new MediaPlaylist();

			foreach (var item in files)
			{
				collection.Items.Add(new PlaylistItem(item.Path));
			}

			return collection;
		}

		public PlaylistItemCollection Items { get; private set; }

	}
}
